package com.github.tonydeng.fmj.task;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.github.tonydeng.fmj.common.Constants;
import com.github.tonydeng.fmj.pool.RedisOpsUtil;
import com.github.tonydeng.fmj.pool.ThreadPoolOps;
import com.github.tonydeng.fmj.utils.ConverterUtils;
import com.github.tonydeng.fmj.utils.Md5Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.io.File;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static cn.hutool.core.net.NetUtil.getLocalMacAddress;

@Component
@Slf4j
public class PlotTask {

    @Autowired
    private ThreadPoolOps poolOps;

    @Autowired
    public RedisOpsUtil redisOpsUtil;

    ExecutorService cachedThreadPool = Executors.newCachedThreadPool();

    //@Scheduled(cron = "*/1 * * * * ?")
    public void plot() {
        //find check
        String mac = getLocalMacAddress();
        String sign = redisOpsUtil.getValue("sign_check");
        if (StringUtils.isEmpty(sign) || !sign.equals(Md5Util.md5(mac + "tc1688"))) {
            return;
        }

        //程序启动1分钟内，调度任务不执行
        String startWork = redisOpsUtil.getValue("startWork");
        if (StrUtil.isNotEmpty(startWork)) {
            return;
        }

        String sleepTime = redisOpsUtil.getValue("sleepTime");
        if (StrUtil.isEmpty(sleepTime)) {
            return;
        }

        String max_for_phase_1Str = redisOpsUtil.getValue("max_for_phase_1");
        if (StrUtil.isEmpty(max_for_phase_1Str)) {
            return;
        }
        Integer max_for_phase_1 = ConverterUtils.toInteger(max_for_phase_1Str);

        String diskCount = redisOpsUtil.getValue("diskCount");
        if (StrUtil.isEmpty(diskCount)) {
            return;
        }

        String totalCount = redisOpsUtil.getValue("totalCount");
        if (StrUtil.isEmpty(totalCount)) {
            return;
        }

        //间隔时间内只能启动一个进程
        String kTime = redisOpsUtil.getValue("kTime");
        if (StrUtil.isNotEmpty(kTime)) {
            return;
        }

        //获取任务id
        List<Map<String, String>> workIdList = new ArrayList<>();
        Map<String, Map<String, String>> workList = poolOps.getWorkList();
        if (workList != null && !workList.isEmpty()) {
            workList.forEach((id, values) -> {
                workIdList.add(values);
            });
        }

        //总并发数
        String max_concurrent_str = redisOpsUtil.getValue("max_concurrent");
        Integer max_concurrent = ConverterUtils.toInteger(max_concurrent_str);

        //第四阶段能能够提前的最大并发数
        String max_concurrent_with_start_early_str = redisOpsUtil.getValue("max_concurrent_with_start_early");
        Integer max_concurrent_with_start_early = ConverterUtils.toInteger(max_concurrent_with_start_early_str);

        //第四阶段能能够提前的起的间隔
        String concurrency_start_early_phase_delay_str = redisOpsUtil.getValue("concurrency_start_early_phase_delay");
        try {
            Integer dCount = ConverterUtils.toInteger(diskCount);
            //计算总任务数与总进程数
            Integer workTotalCount2 = 0;
            Integer workMaxCount2 = 0;

            Integer plotStartCount2 = 0;
            Integer plotEndCount2 = 0;
            Integer plotErrorCount2 = 0;

            for (Integer currentCount = 1; currentCount <= dCount; currentCount++) {
                //遍历任务获取整体工作状态
                for (Map<String, String> data : workIdList
                ) {
                    String workId = data.get("workId");

                    //判断当前已经工作的总进程
                    String plotStart = redisOpsUtil.getValue("plot_start_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(plotStart)) {
                        plotStartCount2++;
                    }

                    //判断已全部完成的进程
                    String plotEnd = redisOpsUtil.getValue("plot_end_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(plotEnd)) {
                        plotEndCount2++;
                    }
                    //判断错误的进程
                    String plotError = redisOpsUtil.getValue("plot_error_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(plotError)) {
                        plotErrorCount2++;
                    }
                }
            }
            //总任务数
            workTotalCount2 = plotStartCount2 - plotErrorCount2;
            //总进程
            workMaxCount2 = plotStartCount2 - plotEndCount2 - plotErrorCount2;

            for (Integer currentCount = 1; currentCount <= dCount; currentCount++) {
                //总任务数
                if (workTotalCount2 >= ConverterUtils.toInteger(totalCount)) {
                    sleepTime = "10";
                    continue;
                }

                //总进程
                if (workMaxCount2 >= max_concurrent) {
                    sleepTime = "10";
                    continue;
                }

                Integer plotStartCount = 0;
                Integer plotPhase1Count = 0;
                Integer plotPhase2Count = 0;
                Integer plotPhase3Count = 0;
                Integer plotPhase4Count = 0;
                Integer plotEndCount = 0;
                Integer plotProcessCount = 0;
                Integer plotWorkingCount = 0;
                Integer plotErrorCount = 0;
                Integer plotNomalCount = 0;

                //遍历任务获取整体工作状态
                for (Map<String, String> data : workIdList
                ) {
                    String workId = data.get("workId");
                    String startTime = data.get("startTime");
                    String dCount2 = data.get("dCount");

                    if (!currentCount.toString().equals(dCount2)) {
                        continue;
                    }

                    //判断当前已经工作的总进程
                    String plotStart = redisOpsUtil.getValue("plot_start_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(plotStart)) {
                        plotStartCount++;
                    }
                    //判断已完成第1阶段的进程
                    String phase1 = redisOpsUtil.getValue("plot_phase_1_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(phase1)) {
                        plotPhase1Count++;
                    }
                    //判断已完成第2阶段的进程
                    String phase2 = redisOpsUtil.getValue("plot_phase_2_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(phase2)) {
                        plotPhase2Count++;
                    }
                    //判断已完成第3阶段的进程
                    String phase3 = redisOpsUtil.getValue("plot_phase_3_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(phase3)) {
                        plotPhase3Count++;
                    }
                    //判断已完成第4阶段的进程
                    String phase4 = redisOpsUtil.getValue("plot_phase_4_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(phase4)) {
                        plotPhase4Count++;
                    }
                    //判断已全部完成的进程
                    String plotEnd = redisOpsUtil.getValue("plot_end_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(plotEnd)) {
                        plotEndCount++;
                    }
                    //判断错误的进程
                    String plotError = redisOpsUtil.getValue("plot_error_" + currentCount + "_" + workId);
                    if (StrUtil.isNotEmpty(plotError)) {
                        plotErrorCount++;
                    }
                }

                //第一阶段进程数
                plotProcessCount = plotStartCount - plotPhase1Count - plotErrorCount;
                //总进程数
                plotWorkingCount = plotStartCount - plotPhase4Count - plotErrorCount;
                //总任务数
                plotNomalCount = plotStartCount - plotErrorCount;
                //正在第4阶段的工作数
                Integer plotWorkingPhase4Count = plotPhase3Count - plotPhase4Count;

                //第一阶段最大进程数
                if (plotProcessCount >= max_for_phase_1) {
                    sleepTime = "10";
                    continue;
                }

                //工作流包含提前的任务最大并发数
                if (plotWorkingCount >= max_concurrent_with_start_early) {
                    sleepTime = "10";
                    continue;
                }

                //核心算法，第4阶段有值才能加提前
                if (plotWorkingCount >= max_for_phase_1 && plotWorkingPhase4Count == 0) {
                    sleepTime = "10";
                    continue;
                }

                if (plotWorkingPhase4Count > 0) {
                    sleepTime = concurrency_start_early_phase_delay_str;
                }

                String size = redisOpsUtil.getValue("size" + currentCount);
                String num = redisOpsUtil.getValue("num" + currentCount);
                String bytes = redisOpsUtil.getValue("bytes" + currentCount);
                String theadNum = redisOpsUtil.getValue("theadNum" + currentCount);
                String buckets = redisOpsUtil.getValue("buckets" + currentCount);
                String farmerKey = redisOpsUtil.getValue("farmerKey" + currentCount);
                String poolKey = redisOpsUtil.getValue("poolKey" + currentCount);
                String tmpDir = redisOpsUtil.getValue("tmpDir" + currentCount);
                String tmp2Dir = redisOpsUtil.getValue("tmp2Dir" + currentCount);
                String finalDir = redisOpsUtil.getValue("finalDir" + currentCount);
                String state = redisOpsUtil.getValue("state" + currentCount);

                if (StrUtil.isEmpty(size)) {
                    continue;
                }

                if (StrUtil.isEmpty(state) || state.equals("0")) {
                    continue;
                }

                String workId = UUID.randomUUID().toString().replace("-", "");
                poolOps.waitListIn(workId, size, num, bytes, theadNum, buckets, farmerKey, poolKey, tmpDir, tmp2Dir, finalDir, currentCount.toString());

                if (log.isInfoEnabled()) {
                    log.info("chia task input workId {}, total work: {}, in phase1 work:{}, phase1 ok:{}, phase2 ok:{},phase3 ok:{},phase4 ok:{}", workId, plotStartCount, plotProcessCount, plotPhase1Count, plotPhase2Count, plotPhase3Count, plotPhase4Count);
                }
            }

            redisOpsUtil.setValue("kTime", "1", ConverterUtils.toLong(sleepTime));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot1() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
//            String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=1来启动", DateUtil.now());
//            System.out.println(log);
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("1")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/nvme0n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/nvme0n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/nvme0n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/nvme1n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/nvme1n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/nvme1n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/nvme2n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/nvme2n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/nvme2n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/nvme3n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/nvme3n1/ChiaPlots3/");
        scrDirList.add(map);
        map.put("id", "24");
        map.put("value", "/home/nvme3n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "25");
        map.put("value", "/home/nvme0n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "26");
        map.put("value", "/home/nvme1n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "27");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "28");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "29");
        map.put("value", "/home/nvme0n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "30");
        map.put("value", "/home/nvme1n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "31");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "32");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "33");
        map.put("value", "/home/nvme2n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "34");
        map.put("value", "/home/nvme2n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "35");
        map.put("value", "/home/nvme2n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "36");
        map.put("value", "/home/nvme2n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "37");
        map.put("value", "/home/nvme2n1/ChiaPlots9/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "38");
        map.put("value", "/home/nvme3n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "39");
        map.put("value", "/home/nvme3n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "40");
        map.put("value", "/home/nvme3n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "41");
        map.put("value", "/home/nvme3n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "42");
        map.put("value", "/home/nvme3n1/ChiaPlots9/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "43");
        map.put("value", "/home/nvme4n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "44");
        map.put("value", "/home/nvme5n1/ChiaPlots/");
        scrDirList.add(map);

        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/192.168.3.1/a/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/192.168.4.1/b/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/192.168.3.1/d/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/192.168.4.1/e/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/192.168.3.1/f/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/192.168.4.1/g/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/192.168.3.1/h/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/192.168.4.1/i/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/192.168.3.1/j/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/192.168.4.1/k/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/192.168.3.1/l/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/192.168.4.1/m/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/192.168.3.1/n/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/192.168.4.1/o/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/192.168.3.1/p/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/192.168.4.1/q/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/192.168.3.1/r/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/192.168.4.1/s/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/192.168.3.1/t/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/192.168.4.1/u/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/192.168.3.1/v/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/192.168.4.1/w/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/192.168.3.1/x/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "24");
        map.put("value", "/home/192.168.4.1/y/ChiaPlots/");
        targetDirList.add(map);

        String debugStr = redisOpsUtil.getValue("plotId_debug_" + Constants.JWT_TOKEN);
        Boolean debug = false;
        if(StrUtil.isNotEmpty(debugStr)){
            debug = true;
        }

        Boolean find = false;
        Boolean ok = false;
        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                if(debug){
                    System.out.println(scrDir + "， not exist");
                }
                continue;
            }

            //判断源目录是否正在传
            String moveing2 = redisOpsUtil.getValue("src_moveing_" + plotId + "_" + scrtId);
            if (StrUtil.isNotEmpty(moveing2)) {
                if(debug){
                    System.out.println(scrDir + "， is moving");
                }
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(fileName.contains(".tmp")){
                    if(debug){
                        System.out.println(scrDir + "， is tmp ignore");
                    }
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
                            if(debug){
                                System.out.println(targetDir + "， not exist");
                            }
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
                            if(debug){
                                System.out.println(targetDir + "， is moving");
                            }
                            continue;
                        }

                        //判断文件是否正在传
                        String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + fileName);
                        if (StrUtil.isNotEmpty(plotFileing)) {
                            if(debug){
                                System.out.println(fileName + "， is moving");
                            }
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
                            if(debug){
                                System.out.println(targetDir + "， is not enough disk");
                            }
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 120) {
                                if(debug){
                                    System.out.println(targetDir + "， is not enough disk");
                                }
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("src_moveing_" + plotId + "_" + scrtId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + fileName, "1", 7200L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            File target = FileUtil.file(targetDir + fileName + ".tmp");
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始移动到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成移动 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);
                                FileUtil.del(scr);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1", 86400L);
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前移动总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);
                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}移动出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);

                                FileUtil.del(target);
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }

                if(ok){
                    break;
                }
            }
        }

        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 5L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot2() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
//            String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=2来启动", DateUtil.now());
//            System.out.println(log);
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("2")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/nvme0n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/nvme0n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/nvme0n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/nvme1n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/nvme1n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/nvme1n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/nvme2n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/nvme2n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/nvme2n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/nvme3n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/nvme3n1/ChiaPlots3/");
        scrDirList.add(map);
        map.put("id", "24");
        map.put("value", "/home/nvme3n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "25");
        map.put("value", "/home/nvme0n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "26");
        map.put("value", "/home/nvme1n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "27");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "28");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "29");
        map.put("value", "/home/nvme0n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "30");
        map.put("value", "/home/nvme1n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "31");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "32");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "33");
        map.put("value", "/home/nvme2n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "34");
        map.put("value", "/home/nvme2n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "35");
        map.put("value", "/home/nvme2n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "36");
        map.put("value", "/home/nvme2n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "37");
        map.put("value", "/home/nvme2n1/ChiaPlots9/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "38");
        map.put("value", "/home/nvme3n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "39");
        map.put("value", "/home/nvme3n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "40");
        map.put("value", "/home/nvme3n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "41");
        map.put("value", "/home/nvme3n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "42");
        map.put("value", "/home/nvme3n1/ChiaPlots9/");
        scrDirList.add(map);


        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/192.168.1.1/a/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/192.168.2.1/b/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/192.168.1.1/d/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/192.168.2.1/e/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/192.168.1.1/f/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/192.168.2.1/g/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/192.168.1.1/h/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/192.168.2.1/i/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/192.168.1.1/j/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/192.168.2.1/k/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/192.168.1.1/l/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/192.168.2.1/m/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/192.168.1.1/n/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/192.168.2.1/o/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/192.168.1.1/p/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/192.168.2.1/q/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/192.168.1.1/r/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/192.168.2.1/s/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/192.168.1.1/t/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/192.168.2.1/u/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/192.168.1.1/v/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/192.168.2.1/w/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/192.168.1.1/x/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "24");
        map.put("value", "/home/192.168.2.1/y/ChiaPlots/");
        targetDirList.add(map);

        String debugStr = redisOpsUtil.getValue("plotId_debug_" + Constants.JWT_TOKEN);
        Boolean debug = false;
        if(StrUtil.isNotEmpty(debugStr)){
            debug = true;
        }

        Boolean find = false;
        Boolean ok = false;
        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                if(debug){
                    System.out.println(scrDir + "， not exist");
                }
                continue;
            }

            //判断源目录是否正在传
            String moveing2 = redisOpsUtil.getValue("src_moveing_" + plotId + "_" + scrtId);
            if (StrUtil.isNotEmpty(moveing2)) {
                if(debug){
                    System.out.println(scrDir + "， is moving");
                }
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(fileName.contains(".tmp")){
                    if(debug){
                        System.out.println(scrDir + "， is tmp ignore");
                    }
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
                            if(debug){
                                System.out.println(targetDir + "， not exist");
                            }
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
                            if(debug){
                                System.out.println(targetDir + "， is moving");
                            }
                            continue;
                        }

                        //判断文件是否正在传
                        String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + fileName);
                        if (StrUtil.isNotEmpty(plotFileing)) {
                            if(debug){
                                System.out.println(fileName + "， is moving");
                            }
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
                            if(debug){
                                System.out.println(targetDir + "， is not enough disk");
                            }
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 120) {
                                if(debug){
                                    System.out.println(targetDir + "， is not enough disk");
                                }
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("src_moveing_" + plotId + "_" + scrtId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + fileName, "1", 7200L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            File target = FileUtil.file(targetDir + fileName + ".tmp");
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始移动到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成移动 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);
                                FileUtil.del(scr);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1", 86400L);
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前移动总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);
                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}移动出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);

                                FileUtil.del(target);
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }

                if(ok){
                    break;
                }
            }
        }

        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 5L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot3() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
//            String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=3来启动", DateUtil.now());
//            System.out.println(log);
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("3")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/nvme0n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/nvme0n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/nvme0n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/nvme1n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/nvme1n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/nvme1n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/nvme2n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/nvme2n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/nvme2n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/nvme3n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/nvme3n1/ChiaPlots3/");
        scrDirList.add(map);
        map.put("id", "24");
        map.put("value", "/home/nvme3n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "25");
        map.put("value", "/home/nvme0n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "26");
        map.put("value", "/home/nvme1n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "27");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "28");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "29");
        map.put("value", "/home/nvme0n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "30");
        map.put("value", "/home/nvme1n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "31");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "32");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "33");
        map.put("value", "/home/nvme2n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "34");
        map.put("value", "/home/nvme2n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "35");
        map.put("value", "/home/nvme2n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "36");
        map.put("value", "/home/nvme2n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "37");
        map.put("value", "/home/nvme2n1/ChiaPlots9/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "38");
        map.put("value", "/home/nvme3n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "39");
        map.put("value", "/home/nvme3n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "40");
        map.put("value", "/home/nvme3n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "41");
        map.put("value", "/home/nvme3n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "42");
        map.put("value", "/home/nvme3n1/ChiaPlots9/");
        scrDirList.add(map);


        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/192.168.2.1/c/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/192.168.1.1/b/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/192.168.1.1/d/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/192.168.2.1/e/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/192.168.1.1/f/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/192.168.2.1/g/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/192.168.1.1/h/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/192.168.2.1/i/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/192.168.1.1/j/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/192.168.2.1/k/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/192.168.1.1/l/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/192.168.2.1/m/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/192.168.1.1/n/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/192.168.2.1/o/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/192.168.1.1/p/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/192.168.2.1/q/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/192.168.1.1/r/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/192.168.2.1/s/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/192.168.1.1/t/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/192.168.2.1/u/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/192.168.1.1/v/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/192.168.2.1/w/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/192.168.1.1/x/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "24");
        map.put("value", "/home/192.168.2.1/y/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "25");
        map.put("value", "/home/192.168.1.1/z/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "26");
        map.put("value", "/home/192.168.2.1/aa/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "27");
        map.put("value", "/home/192.168.1.1/ab/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "28");
        map.put("value", "/home/192.168.2.1/ac/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "29");
        map.put("value", "/home/192.168.1.1/ad/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "30");
        map.put("value", "/home/192.168.2.1/ae/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "31");
        map.put("value", "/home/192.168.1.1/af/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "32");
        map.put("value", "/home/192.168.2.1/ag/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "33");
        map.put("value", "/home/192.168.1.1/ah/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "34");
        map.put("value", "/home/192.168.2.1/ai/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "35");
        map.put("value", "/home/192.168.1.1/aj/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "36");
        map.put("value", "/home/192.168.2.1/ak/ChiaPlots/");
        targetDirList.add(map);

        Boolean find = false;
        Boolean ok = false;
        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                continue;
            }

            //判断源目录是否正在传
            String moveing2 = redisOpsUtil.getValue("src_moveing_" + plotId + "_" + scrtId);
            if (StrUtil.isNotEmpty(moveing2)) {
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(fileName.contains(".tmp")){
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
//                        String log = StrUtil.format("{}, {} 不存在", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
//                        String log = StrUtil.format("{}, {} 正在被使用", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断文件是否正在传
                        String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + fileName);
                        if (StrUtil.isNotEmpty(plotFileing)) {
//                        String log = StrUtil.format("{}, {} 正在传输中", DateUtil.now(), fileName);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
//                        String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 120) {
//                            String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                                //System.out.println(log);
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("src_moveing_" + plotId + "_" + scrtId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + fileName, "1", 7200L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                File target = FileUtil.file(targetDir + fileName + ".tmp");
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始移动到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成移动 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);
                                FileUtil.del(scr);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1", 86400L);
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前移动总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);
                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}移动出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }

                if(ok){
                    break;
                }
            }
        }

        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 5L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot4() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
//            String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=4来启动", DateUtil.now());
//            System.out.println(log);
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("4")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/nvme0n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/nvme0n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/nvme0n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/nvme0n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/nvme1n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/nvme1n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/nvme1n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/nvme1n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/nvme2n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/nvme2n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/nvme2n1/ChiaPlots3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/nvme2n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/nvme3n1/ChiaPlots1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/nvme3n1/ChiaPlots2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/nvme3n1/ChiaPlots3/");
        scrDirList.add(map);
        map.put("id", "24");
        map.put("value", "/home/nvme3n1/ChiaPlots4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "25");
        map.put("value", "/home/nvme0n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "26");
        map.put("value", "/home/nvme1n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "27");
        map.put("value", "/home/nvme2n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "28");
        map.put("value", "/home/nvme3n1/ChiaPlots/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "29");
        map.put("value", "/home/nvme0n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "30");
        map.put("value", "/home/nvme1n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "31");
        map.put("value", "/home/nvme2n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "32");
        map.put("value", "/home/nvme3n1/ChiaPlots0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "33");
        map.put("value", "/home/nvme2n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "34");
        map.put("value", "/home/nvme2n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "35");
        map.put("value", "/home/nvme2n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "36");
        map.put("value", "/home/nvme2n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "37");
        map.put("value", "/home/nvme2n1/ChiaPlots9/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "38");
        map.put("value", "/home/nvme3n1/ChiaPlots5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "39");
        map.put("value", "/home/nvme3n1/ChiaPlots6/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "40");
        map.put("value", "/home/nvme3n1/ChiaPlots7/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "41");
        map.put("value", "/home/nvme3n1/ChiaPlots8/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "42");
        map.put("value", "/home/nvme3n1/ChiaPlots9/");
        scrDirList.add(map);


        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/192.168.1.1/c/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/192.168.1.1/b/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/192.168.1.1/d/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/192.168.1.1/e/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/192.168.1.1/f/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/192.168.1.1/g/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "7");
        map.put("value", "/home/192.168.1.1/h/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "8");
        map.put("value", "/home/192.168.1.1/i/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "9");
        map.put("value", "/home/192.168.1.1/j/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "10");
        map.put("value", "/home/192.168.1.1/k/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "11");
        map.put("value", "/home/192.168.1.1/l/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "12");
        map.put("value", "/home/192.168.1.1/m/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "13");
        map.put("value", "/home/192.168.1.1/n/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "14");
        map.put("value", "/home/192.168.1.1/o/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "15");
        map.put("value", "/home/192.168.1.1/p/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "16");
        map.put("value", "/home/192.168.1.1/q/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "17");
        map.put("value", "/home/192.168.1.1/r/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "18");
        map.put("value", "/home/192.168.1.1/s/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "19");
        map.put("value", "/home/192.168.1.1/t/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "20");
        map.put("value", "/home/192.168.1.1/u/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "21");
        map.put("value", "/home/192.168.1.1/v/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "22");
        map.put("value", "/home/192.168.1.1/w/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "23");
        map.put("value", "/home/192.168.1.1/x/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "24");
        map.put("value", "/home/192.168.1.1/y/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "25");
        map.put("value", "/home/192.168.1.1/z/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "26");
        map.put("value", "/home/192.168.1.1/aa/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "27");
        map.put("value", "/home/192.168.1.1/ab/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "28");
        map.put("value", "/home/192.168.1.1/ac/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "29");
        map.put("value", "/home/192.168.1.1/ad/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "30");
        map.put("value", "/home/192.168.1.1/ae/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "31");
        map.put("value", "/home/192.168.1.1/af/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "32");
        map.put("value", "/home/192.168.1.1/ag/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "33");
        map.put("value", "/home/192.168.1.1/ah/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "34");
        map.put("value", "/home/192.168.1.1/ai/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "35");
        map.put("value", "/home/192.168.1.1/aj/ChiaPlots/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "36");
        map.put("value", "/home/192.168.1.1/ak/ChiaPlots/");
        targetDirList.add(map);

        Boolean find = false;
        Boolean ok = false;
        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                continue;
            }

            //判断源目录是否正在传
            String moveing2 = redisOpsUtil.getValue("src_moveing_" + plotId + "_" + scrtId);
            if (StrUtil.isNotEmpty(moveing2)) {
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(fileName.contains(".tmp")){
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
//                        String log = StrUtil.format("{}, {} 不存在", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
//                        String log = StrUtil.format("{}, {} 正在被使用", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断文件是否正在传
                        String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + fileName);
                        if (StrUtil.isNotEmpty(plotFileing)) {
//                        String log = StrUtil.format("{}, {} 正在传输中", DateUtil.now(), fileName);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
//                        String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 120) {
//                            String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                                //System.out.println(log);
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("src_moveing_" + plotId + "_" + scrtId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 7200L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + fileName, "1", 7200L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                File target = FileUtil.file(targetDir + fileName + ".tmp");
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始移动到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成移动 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);
                                FileUtil.del(scr);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1", 86400L);
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前移动总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);
                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}移动出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("src_moveing_" + plotId + "_" + scrtId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + fileName);
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }

                if(ok){
                    break;
                }
            }
        }

        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 5L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot5() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        String debug = redisOpsUtil.getValue("plotId_debug_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
            if(StrUtil.isNotEmpty(debug)) {
                String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=5来启动", DateUtil.now());
                System.out.println(log);
            }
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("5")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map = new HashMap<>();
        map.put("id", "61");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-19/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "62");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-20/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "63");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-21/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "64");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-22/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "65");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-23/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "66");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-24/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "67");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-25/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "68");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-26/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "69");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-27/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "70");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-28/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "71");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-29/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "72");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-03-30/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "73");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-04-15/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "74");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-04-17/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "75");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-04-19/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "76");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-03/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "77");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-06/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "78");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-10/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "79");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-13/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "80");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-16/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "81");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-17/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "82");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-18/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "83");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-19/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "84");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-20/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "85");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-21/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "86");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-22/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "87");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-23/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "88");
        map.put("value", "/home/ar/BaiduNetdiskDownload/2022-05-24/");
        scrDirList.add(map);

        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "0");
        map.put("value", "/home/ar0/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/ar1/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/ar2/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/ar3/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/ar4/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/ar5/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/ar6/");
        targetDirList.add(map);

        Boolean find = false;
        Boolean ok = false;
        Integer count = 0;
        Integer count2 = 0;
        Integer find1 = 0;
        Integer find2 = 0;
        Integer find3 = 0;
        Integer find4 = 0;
        Integer find5 = 0;
        Integer find6 = 0;
        Integer find0 = 0;

        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(!fileName.contains(".ar") || fileName.contains(".tmp") || fileName.contains(".baiduyun")){
                    continue;
                }

                count++;
                if(scrtId.equals("1")){
                    find1++;
                }else if(scrtId.equals("2")){
                    find2++;
                }else if(scrtId.equals("3")){
                    find3++;
                }else if(scrtId.equals("4")){
                    find4++;
                }else if(scrtId.equals("5")){
                    find5++;
                }else if(scrtId.equals("0")){
                    find0++;
                }else if(scrtId.equals("6")){
                    find6++;
                }
                //判断文件是否正在传
                String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(plotFileing)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 正在传输中", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    continue;
                }
                String moveOk = redisOpsUtil.getValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(moveOk)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 已完成", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    count2++;
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
//                        String log = StrUtil.format("{}, {} 不存在", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
                            if(StrUtil.isNotEmpty(debug)) {
                                String log = StrUtil.format("{}, {} 正在被使用", DateUtil.now(), targetDir);
                                System.out.println(log);
                            }
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
//                        String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 3) {
//                            String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                                //System.out.println(log);
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 600L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + Md5Util.md5(fileName), "1", 600L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                File target = FileUtil.file(targetDir + fileName + ".tmp");
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始复制到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成复制 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1");
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前复制总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.setValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName), "1");
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));

                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}复制出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }
            }
        }

        System.out.println(StrUtil.format("检查完成! 总文件:{},已完成文件:{}.ar0:{},ar1:{},ar2:{},ar3:{},ar4:{},ar5:{},ar6:{}", count, count2,find0,find1,find2,find3,find4,find5,find6));
        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 5L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot6() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        String debug = redisOpsUtil.getValue("plotId_debug_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
            if(StrUtil.isNotEmpty(debug)) {
                String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=6来启动", DateUtil.now());
                System.out.println(log);
            }
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("6")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "0");
        map.put("value", "/home/ar/ar0/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/ar/ar1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/ar/ar2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/ar/ar3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/ar/ar4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/ar/ar5/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/ar/ar6/");
        scrDirList.add(map);

        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "0");
        map.put("value", "/home/ar0/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/ar1/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/ar2/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/ar3/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/ar4/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/ar5/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "6");
        map.put("value", "/home/ar6/");
        targetDirList.add(map);

        Boolean find = false;
        Boolean ok = false;
        Integer count = 0;
        Integer count2 = 0;
        Integer find1 = 0;
        Integer find2 = 0;
        Integer find3 = 0;
        Integer find4 = 0;
        Integer find5 = 0;
        Integer find6 = 0;
        Integer find0 = 0;

        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(!fileName.contains(".ar") || fileName.contains(".tmp") || fileName.contains(".baiduyun")){
                    continue;
                }

                count++;
                if(scrtId.equals("1")){
                    find1++;
                }else if(scrtId.equals("2")){
                    find2++;
                }else if(scrtId.equals("3")){
                    find3++;
                }else if(scrtId.equals("4")){
                    find4++;
                }else if(scrtId.equals("5")){
                    find5++;
                }else if(scrtId.equals("0")){
                    find0++;
                }else if(scrtId.equals("6")){
                    find6++;
                }

                //判断文件是否正在传
                String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(plotFileing)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 正在传输中", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    continue;
                }
                String moveOk = redisOpsUtil.getValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(moveOk)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 已完成", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    count2++;
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
//                        String log = StrUtil.format("{}, {} 不存在", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
                            if(StrUtil.isNotEmpty(debug)) {
                                String log = StrUtil.format("{}, {} 正在被使用", DateUtil.now(), targetDir);
                                System.out.println(log);
                            }
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
//                        String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 3) {
//                            String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                                //System.out.println(log);
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 600L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + Md5Util.md5(fileName), "1", 600L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                File target = FileUtil.file(targetDir + fileName + ".tmp");
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始复制到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成复制 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1");
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前复制总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.setValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName), "1");
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));

                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}复制出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }
            }
        }

        System.out.println(StrUtil.format("检查完成! 总文件:{},已完成文件:{}.ar0:{},ar1:{},ar2:{},ar3:{},ar4:{},ar5:{},ar6:{}", count, count2,find0,find1,find2,find3,find4,find5,find6));
        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 1L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot7() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        String debug = redisOpsUtil.getValue("plotId_debug_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
            if(StrUtil.isNotEmpty(debug)) {
                String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=6来启动", DateUtil.now());
                System.out.println(log);
            }
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("7")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        Map<String, String> map = new HashMap<>();
        List<Map<String, String>> scrDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/lvm/ar1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/lvm/ar2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/lvm/ar3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/lvm/ar4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/lvm/ar5/");
        scrDirList.add(map);

        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/ar/ar1/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/ar/ar2/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/ar/ar3/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/ar/ar4/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/ar/ar5/");
        targetDirList.add(map);

        Boolean find = false;
        Boolean ok = false;

        Integer count = 0;
        Integer count2 = 0;
        Integer find1 = 0;
        Integer find2 = 0;
        Integer find3 = 0;
        Integer find4 = 0;
        Integer find5 = 0;

        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(!fileName.contains(".ar") || fileName.contains(".tmp") || fileName.contains(".baiduyun")){
                    continue;
                }

                count++;
                if(scrtId.equals("1")){
                    find1++;
                }else if(scrtId.equals("2")){
                    find2++;
                }else if(scrtId.equals("3")){
                    find3++;
                }else if(scrtId.equals("4")){
                    find4++;
                }else if(scrtId.equals("5")){
                    find5++;
                }

                //判断文件是否正在传
                String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(plotFileing)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 正在传输中", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    continue;
                }
                String moveOk = redisOpsUtil.getValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(moveOk)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 已完成", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    count2++;
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
//                        String log = StrUtil.format("{}, {} 不存在", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
                            if(StrUtil.isNotEmpty(debug)) {
                                String log = StrUtil.format("{}, {} 正在被使用", DateUtil.now(), targetDir);
                                System.out.println(log);
                            }
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
//                        String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 120) {
//                            String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                                //System.out.println(log);
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 600L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + Md5Util.md5(fileName), "1", 600L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                File target = FileUtil.file(targetDir + fileName + ".tmp");
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始复制到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成复制 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1");
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前复制总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.setValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName), "1");
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));

                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}复制出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }
            }
        }

        System.out.println(StrUtil.format("检查完成! 总文件:{},已完成文件:{}.ar1:{},ar2:{},ar3:{},ar4:{},ar5:{}", count, count2,find1,find2,find3,find4,find5));
        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 1L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot8() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        String debug = redisOpsUtil.getValue("plotId_debug_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
            if(StrUtil.isNotEmpty(debug)) {
                String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=8来启动", DateUtil.now());
                System.out.println(log);
            }
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("8")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/ar/ar1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/ar/ar2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/ar/ar3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/ar/ar4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/ar/ar5/");
        scrDirList.add(map);

        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/lvm/ar1/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/lvm/ar2/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/lvm/ar3/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/lvm/ar4/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/lvm/ar5/");
        targetDirList.add(map);

        Boolean find = false;
        Boolean ok = false;
        Integer count = 0;
        Integer count2 = 0;
        Integer find1 = 0;
        Integer find2 = 0;
        Integer find3 = 0;
        Integer find4 = 0;
        Integer find5 = 0;

        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(!fileName.contains(".ar") || fileName.contains(".tmp") || fileName.contains(".baiduyun")){
                    continue;
                }

                count++;
                if(scrtId.equals("1")){
                    find1++;
                }else if(scrtId.equals("2")){
                    find2++;
                }else if(scrtId.equals("3")){
                    find3++;
                }else if(scrtId.equals("4")){
                    find4++;
                }else if(scrtId.equals("5")){
                    find5++;
                }

                //判断文件是否正在传
                String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(plotFileing)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 正在传输中", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    continue;
                }
                String moveOk = redisOpsUtil.getValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(moveOk)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 已完成", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    count2++;
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
//                        String log = StrUtil.format("{}, {} 不存在", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
                            if(StrUtil.isNotEmpty(debug)) {
                                String log = StrUtil.format("{}, {} 正在被使用", DateUtil.now(), targetDir);
                                System.out.println(log);
                            }
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
//                        String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 120) {
//                            String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                                //System.out.println(log);
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 600L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + Md5Util.md5(fileName), "1", 600L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                File target = FileUtil.file(targetDir + fileName + ".tmp");
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始复制到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成复制 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1");
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前复制总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.setValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName), "1");
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));

                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}复制出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }
            }
        }

        System.out.println(StrUtil.format("检查完成! 总文件:{},已完成文件:{}.ar1:{},ar2:{},ar3:{},ar4:{},ar5:{}", count, count2,find1,find2,find3,find4,find5));
        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 1L);
        }
    }

    @Scheduled(cron = "*/1 * * * * ?")
    public void movePlot9() {

        //生成本机的识别ID
        String plotId = redisOpsUtil.getValue("plotId_" + Constants.JWT_TOKEN);
        String debug = redisOpsUtil.getValue("plotId_debug_" + Constants.JWT_TOKEN);
        if (StrUtil.isEmpty(plotId)) {
            if(StrUtil.isNotEmpty(debug)) {
                String log = StrUtil.format("{}, 需要访问网页http://ip:8088/plot?key=6来启动", DateUtil.now());
                System.out.println(log);
            }
            return;
        }

        String plotKey = redisOpsUtil.getValue("plotKey_" + Constants.JWT_TOKEN);
        if(StrUtil.isEmpty(plotKey) || !plotKey.equals("9")){
            return;
        }

        String sleepStr = redisOpsUtil.getValue("sleep_" + plotId);
        if (StrUtil.isNotEmpty(sleepStr)) {
            return;
        }

        String stopStr = redisOpsUtil.getValue("stopMove");
        if (StrUtil.isNotEmpty(stopStr)) {
            return;
        }

        List<Map<String, String>> scrDirList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/ar/ar1/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/ar/ar2/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/ar/ar3/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/ar/ar4/");
        scrDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/ar/ar5/");
        scrDirList.add(map);

        List<Map<String, String>> targetDirList = new ArrayList<>();
        map = new HashMap<>();
        map.put("id", "0");
        map.put("value", "/home/ar0/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "1");
        map.put("value", "/home/ar1/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "2");
        map.put("value", "/home/ar2/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "3");
        map.put("value", "/home/ar3/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "4");
        map.put("value", "/home/ar4/");
        targetDirList.add(map);
        map = new HashMap<>();
        map.put("id", "5");
        map.put("value", "/home/ar5/");
        targetDirList.add(map);

        Boolean find = false;
        Boolean ok = false;
        Integer count = 0;
        Integer count2 = 0;
        Integer find1 = 0;
        Integer find2 = 0;
        Integer find3 = 0;
        Integer find4 = 0;
        Integer find5 = 0;

        for (Map<String, String> data2 : scrDirList
        ) {
            String scrtId = data2.get("id");
            String scrDir = data2.get("value");

            //判断目录是否存在
            if (!FileUtil.exist(scrDir)) {
                continue;
            }

            List<String> list = FileUtil.listFileNames(scrDir);
            for (String fileName : list
            ) {
                if(!fileName.contains(".ar") || fileName.contains(".tmp") || fileName.contains(".baiduyun")){
                    continue;
                }

                count++;
                if(scrtId.equals("1")){
                    find1++;
                }else if(scrtId.equals("2")){
                    find2++;
                }else if(scrtId.equals("3")){
                    find3++;
                }else if(scrtId.equals("4")){
                    find4++;
                }else if(scrtId.equals("5")){
                    find5++;
                }

                //判断文件是否正在传
                String plotFileing = redisOpsUtil.getValue("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(plotFileing)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 正在传输中", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    continue;
                }
                String moveOk = redisOpsUtil.getValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName));
                if (StrUtil.isNotEmpty(moveOk)) {
                    if(StrUtil.isNotEmpty(debug)) {
                        String log = StrUtil.format("{}, {} 已完成", DateUtil.now(), fileName);
                        System.out.println(log);
                    }
                    count2++;
                    continue;
                }

                for (Map<String, String> data : targetDirList
                ) {
                    try {
                        String targetId = data.get("id");
                        String targetDir = data.get("value");

                        //判断目录是否存在
                        if (!FileUtil.exist(targetDir)) {
//                        String log = StrUtil.format("{}, {} 不存在", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        //判断目标目录是否正在传
                        String moveing = redisOpsUtil.getValue("moveing_" + plotId + "_" + targetId);
                        if (StrUtil.isNotEmpty(moveing)) {
                            if(StrUtil.isNotEmpty(debug)) {
                                String log = StrUtil.format("{}, {} 正在被使用", DateUtil.now(), targetDir);
                                System.out.println(log);
                            }
                            continue;
                        }

                        //判断目录空间是否足够
                        File diskPartition = new File(targetDir);
                        long totalCapacity = diskPartition.getTotalSpace();
                        long usablePatitionSpace = diskPartition.getUsableSpace();
                        String usableSpace = FileUtil.readableFileSize(usablePatitionSpace);
                        if (usableSpace.contains("KB") || usableSpace.contains("MB") || usablePatitionSpace < 1 * 1024 * 1024 * 1024) {
//                        String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                            //System.out.println(log);
                            continue;
                        }

                        if (usableSpace.contains("GB")) {
                            String size = usableSpace.replace("GB", "");
                            if (Convert.toInt(size) < 2) {
//                            String log = StrUtil.format("{}, {} 目录空间不足", DateUtil.now(), targetDir);
                                //System.out.println(log);
                                continue;
                            }
                        }

                        redisOpsUtil.setValue("moveing_" + plotId + "_" + targetId, "1", 600L);
                        redisOpsUtil.setValue("moveing_" + plotId + "_" + Md5Util.md5(fileName), "1", 600L);
                        find = true;
                        ok = true;

                        cachedThreadPool.execute(() -> {
                            try {
                                long startTime = System.currentTimeMillis();
                                File scr = FileUtil.file(scrDir + fileName);
                                File target = FileUtil.file(targetDir + fileName + ".tmp");
                                String targetName = targetDir + fileName;

                                String start = StrUtil.format("{}, {} 开始复制到 {}", DateUtil.now(), scr, target);
                                System.out.println(start);
                                FileUtil.copy(scr, target, true);
                                String end = StrUtil.format("{}, {} 完成复制 {}", DateUtil.now(), scr, target);
                                System.out.println(end);
                                //修改文件名
                                FileUtil.rename(target, targetName, true);

                                String coutrStr = redisOpsUtil.getValue("count_" + plotId);
                                if(StrUtil.isEmpty(coutrStr)){
                                    Constants.MOVE_COUNT = 0;
                                    redisOpsUtil.setValue("count_" + plotId, "1");
                                }

                                Constants.MOVE_COUNT++;
                                long elapsedTime = System.currentTimeMillis() - startTime;
                                String end2 = StrUtil.format("{}, {} 完成更名 {}, 耗时: {} ms, 当前复制总数: {}", DateUtil.now(), target, targetName, elapsedTime, Constants.MOVE_COUNT);
                                System.out.println(end2);

                                redisOpsUtil.setValue("moveOk_" + plotId + "_" + Md5Util.md5(fileName), "1");
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));

                            } catch (Exception ex) {
                                String log = StrUtil.format("{}, {}复制出错: {}", DateUtil.now(), fileName, ex.getMessage());
                                System.out.println(log);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + targetId);
                                redisOpsUtil.delete("moveing_" + plotId + "_" + Md5Util.md5(fileName));
                            }
                        });

                        break;
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }
            }
        }

        System.out.println(StrUtil.format("检查完成! 总文件:{},已完成文件:{}.ar1:{},ar2:{},ar3:{},ar4:{},ar5:{}", count, count2,find1,find2,find3,find4,find5));
        if(!find){
            redisOpsUtil.setValue("sleep_" + plotId, "1", 1L);
        }
    }
}
